<?php

class User_Form_Signup_Account extends Nuo_Form
{

	public function init()
	{

		$this -> setAction(Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array(), 'user_signup', true));
		
		$settings = Nuo::getApi('Setting');

		$this -> addElement('Text', 'email', array(
				'label' => 'email',
				'required' => true,
				'validators' => array('EmailAddress')
		));

		if ($settings -> getSetting('user.signup.email2.enabled', 0))
		{
			$this -> addElement('Text', 'email2', array(
					'label' => 'confirm email',
					'required' => true,
			));
		}

		if ($settings -> getSetting('user.signup.username.enabled', 0))
		{
			$this -> addElement('Text', 'username', array('label' => 'nick'));
		}

		$this -> addElement('Password', 'password', array('label' => 'password'));

		// check password 2
		if ($settings -> getSetting('user.signup.password2.enabled', 0))
		{
			$this -> addElement('Password', 'password2', array('label' => 'confirm password'));

			// Element: timezone
			$this -> addElement('Select', 'timezone', array(
					'label' => 'Timezone',
					'value' => $settings -> getSetting('core.locale.timezone'),
					'multiOptions' => Nuo_Utility_Timezone::getAll(),
			));
		}
		if ($settings -> getSetting('user.signup.terms', 1))
		{

			$this -> addElement('Select', 'language', array(
					'label' => 'Language',
					'multiOptions' => Nuo_Utility_Locale::getLanguageNameList(),
			));
		}
		
		if ($settings -> getSetting('user.signup.terms', 1))
		{
			// Element: terms
			$description = Zend_Registry::get('Zend_Translate') -> _('I have read and agree to the <a target="_blank" href="%s/help/terms">terms of service</a>.');
			$description = sprintf($description, Zend_Controller_Front::getInstance() -> getBaseUrl());

			$this -> addElement('Checkbox', 'terms', array(
					'label' => 'Terms of Service',
					'description' => $description,
					'required' => true,
					'validators' => array(
							'notEmpty',
							array(
									'GreaterThan',
									false,
									array(0)
							),
					),
			));
			$this -> terms -> getValidator('GreaterThan') -> setMessage('You must agree to the terms of service to continue.', 'notGreaterThan');

			$this -> terms -> clearDecorators() -> addDecorator('ViewHelper') -> addDecorator('Description', array(
					'placement' => Zend_Form_Decorator_Abstract::APPEND,
					'tag' => 'label',
					'class' => 'null',
					'escape' => false,
					'for' => 'terms'
			));

			// Init submit
			$this -> addElement('Button', '_submit', array(
					'label' => 'Continue',
					'type' => 'submit',
					'ignore' => true,
			));

		}
	}

}
